package com.mkyong.stock;

import java.util.Date;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name="stock_category",catalog="mkyong")
@AssociationOverrides({
	@AssociationOverride(name="pk.stock",
			joinColumns=@JoinColumn(name="STOCK_ID")),
	@AssociationOverride(name="pk.category",
			joinColumns=@JoinColumn(name="CATEGORY_ID"))
})
public class StockCategory implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private StockCategoryId pk = new StockCategoryId();
	private Date createdDate;
	private String createdBy;
	
	public StockCategory() {
		// TODO Auto-generated constructor stub
	}

	@EmbeddedId
	public StockCategoryId getPk() {
		return pk;
	}

	public void setPk(StockCategoryId pk) {
		this.pk = pk;
	}

	@Transient
	public StockJoinTable getStock(){
		return getPk().getStock();
	}
	
	public void setStock(StockJoinTable stock){
		getPk().setStock(stock);
	}
	
	@Transient
	public CategoryJoinTable getCategory(){
		return getPk().getCategory();
	}
	
	public void setCategory(CategoryJoinTable category){
		getPk().setCategory(category);
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="CREATED_DATE",nullable=false,length=10)
	public Date getCreatedDate() {
		return createdDate;
	}
	
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Column(name="CREATED_BY",nullable=false,length=10)
	public String getCreatedBy() {
		return createdBy;
	}
	
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}
	
	public boolean equals(Object o) {
		if(this == o)
		{
			return true;
		}
		
		if(o == null || getClass() != o.getClass())
		{
			return false;
		}
		
		StockCategory that = (StockCategory) o;
		
		if( getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null)
		{
			return false;
		}
		
		return true;
	}
	
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}
	
}